package com.heima.search.controller;


import cn.hutool.core.map.MapUtil;
import com.heima.model.admin.dto.SensitiveDto;
import com.heima.model.admin.entity.WmSensitive;
import com.heima.model.common.dtos.ResponseResult;
import com.heima.search.service.WmSensitiveService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("api/v1/sensitive")
public class SensitiveController {

    @Autowired
    private WmSensitiveService sensitiveService;


    @PostMapping("save")
    public ResponseResult save(@RequestBody String sensitives) {
        WmSensitive wmSensitive = new WmSensitive();
        sensitives = sensitives.substring(15);
        sensitives = sensitives.substring(0,sensitives.length()-2);
        wmSensitive.setSensitives(sensitives);
        wmSensitive.setCreatedTime(new Date());
        wmSensitive.setUpdatedTime(new Date());
        sensitiveService.insert(wmSensitive);
        return ResponseResult.okResult("添加成功");
    }

    @PostMapping("list")
    public ResponseResult queryList(@RequestBody SensitiveDto dto) {
        return sensitiveService.queryList(dto);
    }

    @PostMapping("update")
    public ResponseResult update(@RequestBody SensitiveDto dto) {

        return sensitiveService.updateById(dto);
    }

    //删除
    @DeleteMapping("del/{id}")
    public ResponseResult deleteById(@PathVariable Long id) {
        sensitiveService.deleteById(Integer.valueOf(id + ""));
        return ResponseResult.okResult("删除成功");
    }


}
